package com.action;

import lombok.Data;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017/2/27.
 */
@Data
public class UploadsAction {
    private String name;
    private File[] face;
    private String[] faceFileName;
    private String[] faceContentType;

    public String execute() throws IOException {

        SimpleDateFormat sdf = new SimpleDateFormat("yyMM");
        String path = ServletActionContext.getServletContext().getRealPath("/upload/" + sdf.format(new Date()));
        File f = new File(path);
        if (!f.exists()) {
            f.mkdirs();
        }
        for (int i = 0; i < face.length; i++) {
            File newface = new File(path, faceFileName[i]);
            FileUtils.copyFile(face[i], newface);
        }
            return null;
    }
}